Keep a cache of the linear version of BablImage's needed for
authorØyvind Kolås <ok@src.gnome.org>
Sun, 11 Nov 2007 14:12:24 +0000 (14:12 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Sun, 11 Nov 2007 14:12:24 +0000 (14:12 +0000)
BablFormats around. This reduces the constant overhead for
conversions.
* babl/babl-classes.h: added .image_template field to BablFormat.
* babl/babl-format.c: (format_new): make .image_template NULL by
defualt.
* babl/babl-image.c: (babl_image_from_linear): use .image_template if
available instead of creating our own BablImage from scratch.
* babl/babl-memory.c: (babl_free): special case freeing of BablImage
and BablFormat to do the extra juggling needed for the image_template
cache.

svn path=/trunk/; revision=248

ChangeLog
babl/babl-classes.h
babl/babl-format.c
babl/babl-image.c
babl/babl-memory.c

index c92fa56e9c47196963289aa460a96d51e660b1e9..ea0e623e92041a50e9e4e89b60c2a32817a416c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2007-11-11  Øyvind Kolås  <pippin@gimp.org>
+
+       Keep a cache of the linear version of BablImage's needed for
+       BablFormats around. This reduces the constant overhead for
+       conversions.
+
+       * babl/babl-classes.h: added .image_template field to BablFormat.
+       * babl/babl-format.c: (format_new): make .image_template NULL by
+       defualt.
+       * babl/babl-image.c: (babl_image_from_linear): use .image_template if
+       available instead of creating our own BablImage from scratch.
+       * babl/babl-memory.c: (babl_free): special case freeing of BablImage
+       and BablFormat to do the extra juggling needed for the image_template
+       cache.
+
 2007-11-10  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-fish-stats.c: (table_destination_each): improve
index 7471b8be4189b6d098ceba79febc348d9adec3e8..dba18e06fe8fdefb8d4df9a8256bca24bcc05342 100644 (file)
@@ -168,6 +168,9 @@ typedef struct
   int              components;
   BablComponent  **component;
   BablType       **type;
+  void            *image_template; /* image template for use with 
+                                       linear (non-planer) images */
+
   BablSampling   **sampling;
   BablModel       *model;
   int              bytes_per_pixel;
@@ -183,8 +186,8 @@ typedef struct
   BablModel      *model;     /*< (always known) */
   int             components;
   BablComponent **component;
-  BablSampling  **sampling;
   BablType      **type;
+  BablSampling  **sampling;
   char          **data;
   int            *pitch;
   int            *stride;
index 702752cde4c111ef012d2e32a8dd98384f61aaca..1fa692308c3d2a0b41fc152138654a4222b3264e 100644 (file)
@@ -102,6 +102,7 @@ component_found:
   }
 
   babl->format.loss = -1.0;
+  babl->format.image_template = NULL;
 
   return babl;
 }
index ad052a32170d504bb82f6d1952d9b85e5c385355..bf9c07cf868b201e93e3a5f3952581418bc001e8 100644 (file)
@@ -91,8 +91,22 @@ babl_image_from_linear (char *buffer,
   switch (format->class_type)
     {
       case BABL_FORMAT:
-        model      = (BablModel *) format->format.model;
         components = format->format.components;
+        if (format->format.image_template != NULL) /* single item cache for speeding
+                                                      up subsequent use of linear buffers
+                                                      for subsequent accesses
+                                                    */
+          { 
+            babl = format->format.image_template;
+            format->format.image_template = NULL;
+            for (i = 0; i < components; i++)
+              {
+                babl->image.data[i] = buffer + offset;
+                offset   += (format->format.type[i]->bits / 8);
+              }
+            return babl;
+          }
+        model      = (BablModel *) format->format.model;
 
         memcpy (component, format->format.component, sizeof (Babl *) * components);
         memcpy (sampling, format->format.sampling, sizeof (Babl *) * components);
@@ -136,7 +150,7 @@ babl_image_from_linear (char *buffer,
     }
 
   babl = image_new (
-    (BablFormat *) format,
+    (BablFormat *) format!=model?format:NULL,
     model, components,
     component, sampling, type, data, pitch, stride);
   return babl;
index d82953eec9dfdf61461eb8887bb8a3f48904731e..3dd2f103f9ad8f784e8a4ec2ca49d088ca696cc3 100644 (file)
@@ -140,6 +140,49 @@ void
 babl_free (void *ptr,
            ...)
 {
+  /* XXX:
+   *  Extra logic to make the bookeeping of BablImage cached
+   *  templates work out correctly, by using a babl_image_destroy
+   *  and custom destroy functions for babl_format this would be
+   *  avoided and the extra overhead not needed for non image/format
+   *  typed allocations.
+   */
+  if (BABL_IS_BABL (ptr))
+    {
+      switch (BABL (ptr)->instance.class_type)
+        {
+        case BABL_IMAGE:
+          {
+            BablFormat *format = BABL(ptr)->image.format;
+            if (format)
+              {
+                if (format->image_template == NULL)
+                  {
+                    format->image_template = ptr;
+                    return;
+                  }
+                else
+                  {
+                  }
+              }
+          }
+          break;
+        case BABL_FORMAT:
+          {
+            BablFormat *format = ptr;
+            if (format->image_template != NULL)
+              {
+                BAI (format->image_template)->signature = NULL;
+                free_f (BAI (format->image_template));
+                frees++;
+              }
+            format->image_template = NULL;
+          }
+          break;
+          default:
+          break;
+        }
+    }
   if (!ptr)
     return;
   if (!IS_BAI (ptr))